﻿<template>
  <a-drawer
    :title="title"
    width="50%"
    :visible="visible"
    @close="
      () => {
        this.visible = false
      }
    "
  >
    <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
      <a-form-model-item label="销售类型编码" prop="cSTCode">
        <a-input v-model="entity.cSTCode" autocomplete="off" placeholder="销售类型编码" />
      </a-form-model-item>
      <a-form-model-item label="销售类型名称" prop="cSTName">
        <a-input v-model="entity.cSTName" autocomplete="off" placeholder="销售类型名称" />
      </a-form-model-item>
      <a-form-model-item label="出库类别编码" prop="cRdCode">
        <a-input v-model="entity.cRdCode" autocomplete="off" placeholder="出库类别编码" />
      </a-form-model-item>
      <a-form-model-item label="是否默认值" prop="bDefault">
        <a-input v-model="entity.bDefault" autocomplete="off" placeholder="是否默认值" />
      </a-form-model-item>
      <!-- <a-form-model-item label="时间戳" prop="pubufts">
        <a-input v-model="entity.pubufts" autocomplete="off" placeholder="时间戳" />
      </a-form-model-item> -->
      <a-form-model-item label="是否列入MPS/MRP计划" prop="bSTMPS_MRP">
        <a-input v-model="entity.bSTMPS_MRP" autocomplete="off" placeholder="是否列入MPS/MRP计划" />
      </a-form-model-item>
    </a-form-model>
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '4px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1
      }"
    >
      <a-button @click="close">取消</a-button>&nbsp;
    </div>
  </a-drawer>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    close() {
      this.visible = false

      this.entity = {}
    },
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/OrderManagement/SaleType/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/OrderManagement/SaleType/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
